# _*_ coding: utf-8 _*_
# .@FileName:GrpBaseSetting
# .@Data....:2025-06-05 : 16 : 33
# .@Aurhor..:LiuJingYu
"""
launch:
from __future__ import unicode_literals, print_function
import maya.cmds as mc
"""
from maya import cmds

rig_top_grp = "rig_top_grp"

if not cmds.objExists(rig_top_grp):
    selections = cmds.ls(sl=True)
    if selections:
        rig_top_grp = selections[0]

# create rig top group attributes
for attr in ['joints', 'editJoint', 'controls', 'controlsVisOnPlayback', 'geometries', 'editGeometries', 'cfxGeometries']:
    if not cmds.objExists(f'{rig_top_grp}.{attr}'):
        cmds.addAttr(rig_top_grp, ln=attr,at='bool',dv=1,keyable=True)

# add resolution
if not cmds.objExists(f'{rig_top_grp}.resolution'):
    cmds.addAttr(rig_top_grp,ln='resolution', at='enum', en='lo:mid:hi',keyable =True)


for idx, res in {0: 'lo', 1: 'mid', 2: 'hi'}.items():
    cnd_node = f'resolution_{res}_conditionNode'
    if not cmds.objExists(cnd_node):
        cnd_node = cmds.createNode('condition', n=cnd_node)

    cmds.connectAttr(f'{rig_top_grp}.resolution', f'{cnd_node}.firstTerm', f=True)
    cmds.setAttr(f'{cnd_node}.secondTerm',idx)
    cmds.setAttr(f'{cnd_node}.colorIfTrueR', 1)
    cmds.setAttr(f'{cnd_node}.colorIfFalseR', 0)

# connect ctrls
ctrls_shapes = cmds.ls('ctrl_*Shape', type = 'nurbsCurve')
for ctrls_shape in ctrls_shapes:
    cmds.connectAttr(f'{rig_top_grp}.controls', f'{ctrls_shape}.visibility', f=True)
    cmds.connectAttr(f'{rig_top_grp}.controlsVisOnPlayback',f'{ctrls_shape}.drawOverride.hideOnPlayback',f=True)

jnts = cmds.ls('jntSkin_*', type= 'joint')
edit_jnts_reverse_node = 'editJoints_reverse'

if not cmds.objExists(edit_jnts_reverse_node):
    edit_jnts_reverse_node = cmds.createNode('reverse', name='editJoints_reverse')
cmds.connectAttr(f'{rig_top_grp}.editJoint',f'{edit_jnts_reverse_node}.inputX',f=True)

for jnt in jnts:
    cmds.setAttr(f'{jnt}.overrideDisplayType', 2)
    cmds.connectAttr(f'{rig_top_grp}.joints', f'{jnt}.visibility', f=True)
    cmds.connectAttr(f'{edit_jnts_reverse_node}.outputX', f'{jnt}.overrideEnabled', f=True)

# connect geometry
cmds.setAttr('GEOS.overrideDisplayType', 2)
cmds.connectAttr(f'{rig_top_grp}.geometries', 'GEOS.v', f=True)
edit_geos_reverse_node = 'editGeometries_reverse'
if not cmds.objExists(edit_geos_reverse_node):
    edit_geos_reverse_node = cmds.createNode('reverse', name='editGeometries_reverse')

cmds.connectAttr(f'{rig_top_grp}.editGeometries', f'{edit_geos_reverse_node}.inputX', f=True)
cmds.connectAttr(f'{edit_geos_reverse_node}.outputX', 'GEOS.overrideEnabled', f=True)














